﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SwenAssigment
{
    public partial class Reporting : System.Web.UI.Page
    {
        public override void VerifyRenderingInServerForm(Control control)
        {

        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GenerateRoomAndStatus_Click(object sender, EventArgs e)
        {
            ExportExcelBtn.Visible = false;
            NoDataFoundLbl.Visible = false;
            GridView1.DataSource = GenerateRoomStatus;
            GridView1.DataBind();
            if (GridView1.Rows.Count != 0)
            {
                ExportExcelBtn.Visible = true;
            }
            else
            {
                NoDataFoundLbl.Visible = true;
            }
        }

        protected void GenerateGuestInRoom_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                NoDataEnteredLbl.Visible = false;
                ExportExcelBtn.Visible = false;
                NoDataFoundLbl.Visible = false;
                if (RoomNumberTbx.Text.Equals(""))
                {
                    NoDataEnteredLbl.Visible = true;
                }
                else
                {
                    GridView1.DataSource = GenerateGuestRoomNum;
                    GridView1.DataBind();
                    if (GridView1.Rows.Count != 0)
                    {
                        ExportExcelBtn.Visible = true;
                    }
                    else
                    {
                        NoDataFoundLbl.Visible = true;
                    }
                }
            }
        }

        protected void GenerateGuestOnWhen_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                NoDataEnteredLbl.Visible = false;
                ExportExcelBtn.Visible = false;
                NoDataFoundLbl.Visible = false;
                if (DateTbx.Text.Equals(""))
                {
                    NoDataEnteredLbl.Visible = true;
                }
                else
                {
                    GridView1.DataSource = GenerateGuestDate;
                    GridView1.DataBind();
                    if (GridView1.Rows.Count != 0)
                    {
                        ExportExcelBtn.Visible = true;
                    }
                    else
                    {
                        NoDataFoundLbl.Visible = true;
                    }
                }
            }
        }

        protected void ExportExcelBtn_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment; filename=FileName.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite =
            new HtmlTextWriter(stringWrite);
            GridView1.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();
        }
    }
}